// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Continue Screen Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 40 : TYPE_CONTINUESCREEN


// Static Values

// Tables

event ObjectMain
	if object.state == 1
		object.value1--
		if object.value1 <= 0
			if object.value0 == 0
				object.state++
				object[-2].state = 7
			else
				object.value0--
				object.value1 = 60
			end if
		end if
	end if
end event


event ObjectDraw
	DrawSprite(0)
	DrawSprite(1)
	temp0 = object.xpos
	temp0 >>= 16
	DrawNumbers(2, temp0, 126, object.value0, 2, 8, 1)
	temp0 = player.continues
	temp1 = temp0
	temp0 -= 2
	temp0 *= 21
	temp0 >>= 1
	FlipSign(temp0)
	temp0 += screen.xcenter
	GetBit(object.frame, oscillation, 4)
	object.frame += 12
	temp3 = 1
	while temp1 > 1
		temp2 = 1
		if temp3 == 1
			temp3 = 0
			if object[-2].state >= 5
				if object[-2].state != 7
					temp2 = 0
				end if
			else
				if object[-2].state > 3
					GetBit(temp2, oscillation, 0)
				end if
			end if
		end if
		if temp2 == 1
			DrawSpriteScreenXY(object.frame, temp0, 100)
		end if
		temp0 += 21
		temp1--
	loop
end event


event ObjectStartup
	LoadSpriteSheet("Continue/Objects.gif")
	SpriteFrame(-59, 64, 118, 16, 1, 15)
	SpriteFrame(-21, 128, 41, 9, 50, 1)
	SpriteFrame(0, 0, 8, 11, 1, 32)
	SpriteFrame(0, 0, 8, 11, 10, 32)
	SpriteFrame(0, 0, 8, 11, 19, 32)
	SpriteFrame(0, 0, 8, 11, 28, 32)
	SpriteFrame(0, 0, 8, 11, 1, 44)
	SpriteFrame(0, 0, 8, 11, 10, 44)
	SpriteFrame(0, 0, 8, 11, 19, 44)
	SpriteFrame(0, 0, 8, 11, 28, 44)
	SpriteFrame(0, 0, 8, 11, 1, 56)
	SpriteFrame(0, 0, 8, 11, 10, 56)
	switch stage.playerListPos
	case 0
	case 3
		SpriteFrame(-8, -11, 16, 23, 37, 32)
		SpriteFrame(-8, -11, 16, 23, 54, 32)
		break
	case 1
		SpriteFrame(-8, -11, 16, 23, 71, 32)
		SpriteFrame(-8, -11, 16, 23, 88, 32)
		break
	case 2
	case 4
		SpriteFrame(-8, -11, 16, 23, 105, 32)
		SpriteFrame(-8, -11, 16, 23, 122, 32)
		break
	case 5
		SpriteFrame(-8, -9, 16, 25, 139, 30)
		SpriteFrame(-8, -9, 16, 25, 157, 30)
		break
	case 6
		SpriteFrame(-8, -11, 16, 23, 75, 56)
		SpriteFrame(-8, -11, 16, 23, 92, 56)
		break
	case 7
		SpriteFrame(-8, -11, 16, 23, 109, 56)
		SpriteFrame(-8, -11, 16, 23, 126, 56)
		break
	case 8
		SpriteFrame(-8, -10, 16, 24, 143, 56)
		SpriteFrame(-8, -10, 16, 24, 160, 56)
		break
	case 9
		SpriteFrame(-9, -10, 18, 24, 37, 56)
		SpriteFrame(-9, -10, 18, 24, 56, 56)
		break
	end switch
	foreach (TypeName[Continue Screen], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 5
		object[arrayPos0].xpos = screen.xcenter
		object[arrayPos0].xpos <<= 16
		object[arrayPos0].ypos = 0
		object[arrayPos0].value0 = 10
	next
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
